Repository navigation
Apply command line options with --resolve-all-configs - #2769
nk-batman21 wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2769 +/- ##
=======================================
Coverage 99.38% 99.39%
=======================================
Files 40 40
Lines 3275 3319 +44
Branches 707 716 +9
=======================================
+ Hits 3255 3299 +44
Misses 12 12
Partials 8 8 🚀 New features to boost your workflow:
|
| config_overrides = { | ||
| key: value | ||
| for key, value in config_dict.items() | ||
| if key not in ("settings_path", "settings_file") | ||
| } |
There was a problem hiding this comment.
Let's do this exclusion in find_all_configs itself. We can add a small sentence in the docstring that says these will be ignored.
There was a problem hiding this comment.
Thanks @DanielNoord, done in b4acb02. find_all_configs now drops settings_path and settings_file from the overrides itself, and the docstring says they are ignored. main passes the CLI options through unchanged, and a new test in test_settings.py calls find_all_configs with both keys.
There was a problem hiding this comment.
🟢 Approved
No active review issues are reported for the changes propagating command-line overrides across project configurations.
No open issues 🎉
What changed in this PR
Fixes command-line option handling with --resolve-all-configs, so overrides apply across per-project configurations and to files without a configuration file.
Changes:
- Pass command-line overrides into configuration discovery and merge them with each discovered configuration.
- Exclude
settings_pathandsettings_fileoverrides to preserve per-project configuration selection. - Add regression tests for override propagation, default behavior, and configuration isolation.
| File | Description |
|---|---|
tests/unit/test_settings.py |
Tests override merging and exclusion of configuration-location options. |
tests/unit/test_main.py |
Tests command-line options across multiple projects and an unconfigured file. |
isort/settings.py |
Applies overrides to discovered configurations and fallback defaults. |
isort/main.py |
Passes command-line options to find_all_configs. |
Review effort: Balanced
With
--resolve-all-configs, each file's config is built only from its nearest config file, so options given on the command line are dropped (--checkand--diffstill work becausemain()handles them itself). Files without a config file get plain defaults. This is easy to hit in a monorepo with per-project config files and shared pre-commit args such as["--resolve-all-configs", "--profile=black"]: the profile is silently ignored.For example, with
pkg/pyproject.tomlcontaining[tool.isort]/line_length = 100andpkg/a.pycontainingfrom os import path, sep,isort --force-single-line-imports pkg/a.pysplits the import, butisort --force-single-line-imports --resolve-all-configs pkg/a.pyleaves it on one line.--profile,--line-lengthand--verboseare ignored the same way (the missing verbose output is the first question in #2045).This passes the command line options to
find_all_configs, which applies them on top of every config file it finds and on the default used for files without one. It follows #2119 by hotpxl and adds the test that was asked for there. Unlike #2119,settings_pathandsettings_fileare not passed on:settings_pathdefaults to the first file's directory, so passing it would load that project's config for files in every other project. The new test covers that case too.Refs #2045 (the
src_pathspart of that issue is separate).Ran:
coverage run -m pytest tests/unit/(the new test fails without the change) and thetox -e lintcommands.